Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend demo bnd-workspace for creation of executable jar via .bndrun #4675

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chrisrueger
Copy link
Contributor

@chrisrueger chrisrueger commented Feb 1, 2025

  • added a .bndrun in the demo.impl bundle which is used to build the executable jar (comparable to building the product)
  • added another consumer bundle which
  • installed Felix Gogo Shell, so that you can even start the application and type 'hello' in the console to get an output from the service. this is basically now a very simple OSGi application
  • changed to Java17
  • removed all warnings in Eclipse
mvn clean verify -Dtycho-version=5.0.0-SNAPSHOT

[INFO] bnd-parent ......................................... SUCCESS [  0.038 s]
[INFO] tycho.demo.api ..................................... SUCCESS [  1.409 s]
[INFO] tycho.demo.consumer ................................ SUCCESS [  1.127 s]
[INFO] tycho.demo.markdown ................................ SUCCESS [  1.469 s]
[INFO] tycho.demo.impl .................................... SUCCESS [  1.219 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

In Eclipse you can start the .bndrun and also Export it as an executable jar like this:

image

The .bndrun can also be created and run for test and comparison purposes via the bnd command line:

cd demo/bnd-workspace
bnd export tycho.demo.impl/tycho.demo.app.bndrun

or just run it as a application:

bnd run tycho.demo.impl/tycho.demo.app.bndrun
which starts the app and shows the Felix Gogo Shell.

____________________________
Welcome to Apache Felix Gogo

g! Please type 'hello' into the console and press Enter, and magic will happen.

Then type 'hello'.

hello
Hello BND Workspace!
Render some markdown to HTML: <h2>H2 Headline</h2>

@chrisrueger chrisrueger force-pushed the add-bndrun-to-demo-bndworkspace branch from ddf14cf to 8c74a50 Compare February 1, 2025 19:48
- added a .bndrun in the demo.impl bundle which is used to build the executable jar (comparable to building the product)
- added another consumer bundle which
- installed Felix Gogo Shell, so that you can even start the application and type 'hello' in the console to get an output from the service. this is basically now a very simple OSGi application
- changed to Java17
- removed all warnings in Eclipse

tweak target-dir with ${driver}
this allows to use different build tools independently
@chrisrueger chrisrueger force-pushed the add-bndrun-to-demo-bndworkspace branch from 8c74a50 to 0ccd052 Compare February 1, 2025 19:58
Copy link

github-actions bot commented Feb 1, 2025

Test Results

  606 files  ±0    606 suites  ±0   4h 0m 52s ⏱️ + 5m 42s
  434 tests ±0    426 ✅  - 1   7 💤 ±0  1 ❌ +1 
1 302 runs  ±0  1 279 ✅  - 1  22 💤 ±0  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 0ccd052. ± Comparison against base commit 9330061.

Copy link
Member

@laeubi laeubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the upcomming support you need to add

-Dbndrun.exports=tycho.demo.app

to the maven.config file.

Also we should not check in the .project/.classpath files as this is a headless demo.

It would also be good the enhance this testcase:

public void testTychoBndWorkspaceDemo() throws Exception {
runDemo("bnd-workspace");
}

to assert that the output file (will be target/tycho.demo.app.zip in this case) is actually produced, this should fail for now and should succeed after we have added support for this.

@@ -1,3 +1,7 @@
Bundle-Version: 1.0.0-SNAPSHOT
-runfw: org.eclipse.osgi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this I get

Exception in thread "main" java.lang.NoClassDefFoundError: org/osgi/framework/ServiceListener
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:714)
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	at aQute.launcher.pre.EmbeddedLauncher.executeWithRunPath(EmbeddedLauncher.java:160)
	at aQute.launcher.pre.EmbeddedLauncher.findAndExecute(EmbeddedLauncher.java:118)
	at aQute.launcher.pre.EmbeddedLauncher.main(EmbeddedLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.ServiceListener
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)

when launching the produced export.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I thought this belongs to .bndrun, as it it about "running" I thought. And I could have e.g. different .bndrun files using different frameworks (felix, equinox).

I found this sentence

...This means the bnd.bnd file must have the necessary -runfw and -runbundles to support the test bundles built by the project. The check task depends on the testOSGi task.

in
https://github.com/bndtools/bnd/blob/master/gradle-plugins/README.md

and an issue created by you: bndtools/bnd#5504

Is this related?

I can put it back of course, if it is needed.
I try to reproduce it locally and maybe compare what bnd CLI is doing with / without it.

@chrisrueger
Copy link
Contributor Author

Also we should not check in the .project/.classpath files as this is a headless demo.

ok, but then it gets hard to extend it. Without Eclipse I would not have been able to develop it... e.g. I need to resolve button to resolve the -runbundles in .bndrun.
Maybe that is an indicator we also need something like bnd-resolver-maven-plugin https://github.com/bndtools/bnd/blob/master/maven-plugins/bnd-resolver-maven-plugin/README.md too in the future.

I guess this is the "thinking" behind the current bnd-maven plugins to be able to develop completely headless. Ideally this would allow a development workflow independent of Eclipse IDE and also use VSCode or whatever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants